package com.example.beerhunterapp;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class ProfilWindow extends Activity{
	
	Intent intentMenu;
	Intent intentScan;
	Intent intentBeerLog;
	Intent intentChallenge;
	MediaPlayer mp1;
	MediaPlayer mp2;
	boolean soundPlay=true;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.profil_activity);
        
        if(InfoProtoypeSingleton.getInstance().getNumberOfBeer()!=2){
        	TextView t = (TextView)findViewById(R.id.beerLogScoreMenuTextView);
        	t.setText(getResources().getText(R.string.beerlogscorenew));
        	TextView t2 = (TextView)findViewById(R.id.profilscore1);
        	t2.setText(getResources().getText(R.string.beerlogscorenew));
        }
        
        mp1 = MediaPlayer.create(this, R.raw.gunload); 
        mp2 = MediaPlayer.create(this, R.raw.gunshot); 
        intentMenu = new Intent(this, MenuWindow.class);
        intentScan = new Intent(this, ScanWindow.class);
        intentBeerLog = new Intent(this, BeerlogWindow.class);
        intentChallenge = new Intent(this, ChallengeWindow.class);
                
        ImageView scanButton = (ImageView) findViewById(R.id.scanButton);
        scanButton.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View view, MotionEvent event) {
				if(event.getAction() == (MotionEvent.ACTION_UP)){
	                //Do whatever you want after press
					((ImageView)view).setImageResource(R.drawable.scanboutonshot);
					mp2.start();
					startActivity(intentScan);
					finish();
	            }
	            else{
	                //Do whatever you want during press  
	            	((ImageView)view).setImageResource(R.drawable.scanbouton2);
	            	if(soundPlay){
		            	mp1.start();
		            	soundPlay=false;
	            	}     	        
	            }
	            return true;
			}

		});
        
        Button beerLogButton = (Button) findViewById(R.id.beerLogButton);
        beerLogButton.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				startActivity(intentBeerLog);
				finish();
			}
        });
        
        Button challengeButton = (Button) findViewById(R.id.challengeButton);
        challengeButton.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				startActivity(intentChallenge);
				finish();
			}
        });
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)  {
        if (keyCode == KeyEvent.KEYCODE_BACK ) {
            // do something on back.
			startActivity(intentMenu);
			finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }    
}
